<?php

namespace addons\qingdongams\model;

use think\Exception;
use think\Model;
use traits\model\SoftDelete;

/**
 *设备表
 */
class Equipment extends Model
{
    use SoftDelete;

    protected $name = 'qingdongams_equipment';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    public function customerProduct()
    {
        return $this->hasOne(CustomerProduct::class, 'id', 'cus_pro_id')->field('id,customer_id,status,pay_date');
    }


    public function getImgAttr($value)
    {
        if ($value) {
            return cdnurl(File::getUrl($value), true);
        } else {
            return $value;
        }
    }

    public function product()
    {
        return $this->hasOne(Product::class, 'id', 'pro_id')->field('id,name,num,img,unit,price,description');
    }

}
